home *** CD-ROM | disk | FTP | other *** search
/ IRIX Patches 1995 June / SGI IRIX Patches 1995 Jun.iso / 5.3_patches / patchSG0000154 / patchSG0000154.idb / usr / share / src / OpenGL / samples / accum.c.z / accum.c
Encoding:
C/C++ Source or Header  |  1995-06-12  |  2.4 KB  |  137 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <unistd.h>
  4. #include <stdlib.h>
  5. #include "tk.h"
  6.  
  7.  
  8. GLenum doubleBuffer, directRender;
  9. GLint thing1, thing2;
  10.  
  11.  
  12. static void Init(void)
  13. {
  14.  
  15.     glClearColor(0.0, 0.0, 0.0, 0.0);
  16.     glClearAccum(0.0, 0.0, 0.0, 0.0);
  17.  
  18.     thing1 = glGenLists(1);
  19.     glNewList(thing1, GL_COMPILE);
  20.     glColor3f(1.0, 0.0, 0.0);
  21.     glRectf(-1.0, -1.0, 1.0, 0.0);
  22.     glEndList();
  23.  
  24.     thing2 = glGenLists(1);
  25.     glNewList(thing2, GL_COMPILE);
  26.     glColor3f(0.0, 1.0, 0.0);
  27.     glRectf(0.0, -1.0, 1.0, 1.0);
  28.     glEndList();
  29. }
  30.  
  31. static void Reshape(int width, int height)
  32. {
  33.  
  34.     glViewport(0, 0, (GLint)width, (GLint)height);
  35.  
  36.     glMatrixMode(GL_PROJECTION);
  37.     glLoadIdentity();
  38.     glMatrixMode(GL_MODELVIEW);
  39.     glLoadIdentity();
  40. }
  41.  
  42. static GLenum Key(int key, GLenum mask)
  43. {
  44.  
  45.     switch (key) {
  46.       case TK_ESCAPE:
  47.     tkQuit();
  48.       case TK_1:
  49.     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  50.     break;
  51.       case TK_2:
  52.     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  53.     break;
  54.       default:
  55.     return GL_FALSE;
  56.     }
  57.     return GL_TRUE;
  58. }
  59.  
  60. static void Draw(void)
  61. {
  62.  
  63.     glPushMatrix();
  64.  
  65.     glScalef(0.8, 0.8, 1.0);
  66.  
  67.     glClear(GL_COLOR_BUFFER_BIT);
  68.     glCallList(thing1);
  69.     glAccum(GL_LOAD, 0.5);
  70.  
  71.     glClear(GL_COLOR_BUFFER_BIT);
  72.     glCallList(thing2);
  73.     glAccum(GL_ACCUM, 0.5);
  74.  
  75.     glAccum(GL_RETURN, 1.0);
  76.  
  77.     glPopMatrix();
  78.  
  79.     glFlush();
  80.  
  81.     if (doubleBuffer) {
  82.     tkSwapBuffers();
  83.     }
  84. }
  85.  
  86. static GLenum Args(int argc, char **argv)
  87. {
  88.     GLint i;
  89.  
  90.     doubleBuffer = GL_FALSE;
  91.     directRender = GL_TRUE;
  92.  
  93.     for (i = 1; i < argc; i++) {
  94.     if (strcmp(argv[i], "-sb") == 0) {
  95.         doubleBuffer = GL_FALSE;
  96.     } else if (strcmp(argv[i], "-db") == 0) {
  97.         doubleBuffer = GL_TRUE;
  98.     } else if (strcmp(argv[i], "-dr") == 0) {
  99.         directRender = GL_TRUE;
  100.     } else if (strcmp(argv[i], "-ir") == 0) {
  101.         directRender = GL_FALSE;
  102.     } else {
  103.         printf("%s (Bad option).\n", argv[i]);
  104.         return GL_FALSE;
  105.     }
  106.     }
  107.     return GL_TRUE;
  108. }
  109.  
  110. void main(int argc, char **argv)
  111. {
  112.     GLenum type;
  113.  
  114.     if (Args(argc, argv) == GL_FALSE) {
  115.     tkQuit();
  116.     }
  117.  
  118.     tkInitPosition(0, 0, 300, 300);
  119.  
  120.     type = TK_RGB | TK_ACCUM;
  121.     type |= (doubleBuffer) ? TK_DOUBLE : TK_SINGLE;
  122.     type |= (directRender) ? TK_DIRECT : TK_INDIRECT;
  123.     tkInitDisplayMode(type);
  124.  
  125.     if (tkInitWindow("Accum Test") == GL_FALSE) {
  126.     tkQuit();
  127.     }
  128.  
  129.     Init();
  130.  
  131.     tkExposeFunc(Reshape);
  132.     tkReshapeFunc(Reshape);
  133.     tkKeyDownFunc(Key);
  134.     tkDisplayFunc(Draw);
  135.     tkExec();
  136. }
  137.